export class lineBar {


    constructor() {
        this.option = {
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'cross',
                    crossStyle: {
                        color: '#999'
                    }
                }
            },
            title: {
                left: 'center',
                text: 'ocv1最终良率'
            },
            legend: {
                data: ['投入', '最终良率'],
                left: 'right'
            },
            xAxis: [
                {
                    type: 'category',
                    data: ['3月', '4月', 'W1', 'W2', '2024/4/6', '2024/4/7', '2024/4/8'],
                    axisPointer: {
                        type: 'shadow'
                    }
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    min: 0,
                    interval: 2000,
                },
                {
                    type: 'value',
                    min: 0,
                    max: 100,
                    interval: 10,
                    axisLabel: {
                        formatter: '{value} %'
                    }
                },


            ],
            series: [
                {
                    name: '投入',
                    type: 'bar',
                    color: '#1bcfc8',
                    tooltip: {
                        valueFormatter: function (value) {
                            return '投入 ' + value;
                        }
                    },
                    data: [
                        2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3
                    ]
                },
                {
                    name: '最终良率',
                    type: 'line',
                    tooltip: {
                        valueFormatter: function (value) {
                            return '良率 ' + value + ' %';
                        }
                    },
                    yAxisIndex: 1, // 这个指定的是哪个y轴 todo
                    color: 'red',
                    data: [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]
                },


            ]
        }
    }

    setTitle(title) {
        this.option.title.text = title
    }

    setLegend(legend) {
        this.option.legend.data = legend

        for (let i = 0; i < this.option.series.length; i++) {

            this.option.series[i].name = legend[i]
        }
    }

    // 设定data
    setData(series) {
        this.option.series = series
    }

    // 设定横坐标
    setXAxis(data) {
        this.option.xAxis[0].data = data
    }

    // 设定纵坐标
    setYAxis(yAxis) {
        this.option.yAxis = yAxis
    }

    // 只设定数据
    setSeriesData(data) {
        if (data.length) {
            for (const dataKey in data) {
                if (data[dataKey].length) {
                    // delete this.option.series[dataKey].yAxisIndex
                    this.option.series[dataKey].data = data[dataKey]
                }
            }
        }
    }


    getChartOption() {
        return this.option
    }
}


export class candlestick {
    constructor() {
        this.option = {
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'cross',
                    crossStyle: {
                        color: '#999'
                    }
                }
            },
            title: {
                text: ""
            },
            xAxis: {
                data: ['E3C', 'E3D', 'E3F', 'E3G', 'E3H']
            },
            yAxis: {},
            series: [
                {
                    color: "#1bcfc8",
                    type: 'candlestick',
                    data: [
                        [20, 34, 10, 38],
                        [40, 35, 30, 50],
                        [31, 38, 33, 44],
                        [38, 15, 5, 42]
                    ]
                }
            ]
        };
    }

    setTitle(title) {
        this.option.title.text = title
    }

    setLegend(legend) {
        this.option.legend.data = legend

        for (let i = 0; i < this.option.series.length; i++) {

            this.option.series[i].name = legend[i]
        }
    }

    // 设定data
    setData(series) {
        this.option.series = series
    }

    // 设定横坐标
    setXAxis(data) {
        this.option.xAxis.data = data
    }

    // 设定纵坐标
    setYAxis(yAxis) {
        this.option.yAxis = yAxis
    }

    // 只设定数据
    setSeriesData(data) {
        if (data.length) {
            for (const dataKey in data) {
                if (data[dataKey].length) {
                    // delete this.option.series[dataKey].yAxisIndex
                    this.option.series[dataKey].data = data[dataKey]
                }
            }
        }
    }


    getChartOption() {
        return this.option
    }

}